package vg.modules.backlight.components;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import vg.core.AUserInterface;
import vg.core.AUserInterfaceElement;
import vg.core.IGraphView;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventChangeView;
import vg.core.exception.PluginException;
import vg.core.plugin.IPlugin;
import vg.core.plugin.PluginParameter;
import vg.core.storableGraph.StorableSubGraph;
import vg.core.storableGraph.StorableVertex;
public class PathsSearcher {
private JButton button;
private IGraphView view;
// -------------------------------------------------------------------------
public PathsSearcher() {
this.button = new JButton(new ImageIcon("./data/resources/textures/paths.png"));
this.button.setToolTipText("Find all paths beetwen two vertices");
this.button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StorableSubGraph ssg = PathsSearcher.this.view.getSelectionSubGraph();
if (ssg != null) {
List<StorableVertex> lsv = ssg.getVertices();
if (lsv != null && lsv.size() == 2) {
StorableVertex sv = lsv.get(0);
StorableVertex sv2 = lsv.get(1);
Object[] possibilities = { "from " + sv.getId() + " to " + sv2.getId(), "from " + sv2.getId() + " to " + sv.getId() };
Object o = JOptionPane.showInputDialog(null, "Path ", "Select direction", JOptionPane.PLAIN_MESSAGE, null,
possibilities, possibilities[0]);
if (o == null)
return;
if (o.equals(possibilities[0]))
PathsSearcher.this.view.showPaths(sv, sv2);
else
PathsSearcher.this.view.showPaths(sv2, sv);
}
}
}
});
this.button.setEnabled(false);
}
// -------------------------------------------------------------------------
public JComponent getView() {
return (this.button);
}
public void setEnabled(boolean enable) {
this.button.setEnabled(enable);
}
public void changeView(IGraphView igv) {
this.view = igv;
if (view == null) {
setEnabled(false);
}
}
}